﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using NodeEditorFramework.Standard;
using NodeEditorFramework;

public class NodeEditorInterfaceEx : NodeEditorInterface
{
    public override void SaveCanvas()
    {
        if (canvasCache.nodeCanvas.GetType() == typeof(LevelMapNodeCanvas))
        {
            var canvas = canvasCache.nodeCanvas as LevelMapNodeCanvas;
            string path = canvasCache.nodeCanvas.savePath;
            string config = canvas.RuntimeConfig;
            if (string.IsNullOrEmpty(path))
            {
                ShowNotification(new GUIContent("没有Canvas存储路径. 使用 'Save As'!"));
            }
            else if (string.IsNullOrEmpty(config))
            {
                ShowNotification(new GUIContent("没有运行时Bundle数据存储路径. 使用 'Save As'!"));
            }

            if (path.StartsWith("SCENE/"))
                canvasCache.SaveSceneNodeCanvas(path.Substring(6));
            else
                canvasCache.SaveNodeCanvas(path);
            ShowNotification(new GUIContent("Canvas Saved!"));
        }
        else
        {
            base.SaveCanvas();
        }
    }

    public override void SaveCanvasAs()
    {
        if (canvasCache.nodeCanvas.GetType() == typeof(LevelMapNodeCanvas))
        {
            var levelMap = canvasCache.nodeCanvas as LevelMapNodeCanvas;
            string panelPath = LevelMapNodeCanvas.levelMapCanvasPath;
            //if (canvasCache.nodeCanvas != null && !string.IsNullOrEmpty(canvasCache.nodeCanvas.savePath))
            //    panelPath = canvasCache.nodeCanvas.savePath;
            string path = UnityEditor.EditorUtility.SaveFilePanelInProject("保存Canvas数据", "SceneConfig", "asset", "", panelPath);
            //if (levelMap != null && !string.IsNullOrEmpty(levelMap.RuntimeConfig))
                panelPath = LevelMapNodeCanvas.levelMapBundlePath;
            levelMap.RuntimeConfig = UnityEditor.EditorUtility.SaveFilePanelInProject("导出运行时 Bundle 数据", "SceneConfig", "xml", "", panelPath);
            
            if (!string.IsNullOrEmpty(path))
                canvasCache.SaveNodeCanvas(path);
        }
        else
        {
            base.SaveCanvasAs();
        }
    }

}
